package leecode.二分法.实现快速幂运算;

public class myPow {
    public static void main(String[] args) {
        Solution solution = new Solution();
        double v = solution.myPow(2, 6);
        System.out.println(v);
    }

    static class Solution {
        public double myPow(double x, int n) {
            double res = 1.0;
            for(int i = n; i != 0; i /= 2){
                if(i % 2 != 0){
                    res *= x;
                }
                x *= x;
            }
            return n < 0 ? 1 / res : res;


        }
    }
}
